<?
	$sess = new Zend_Session_Namespace(CLU_NS); 
?>

<div class="box white_bg">
<br/>
<b>
<?=t(3006)?>
</b>
<hr/>
<br/>
<?if (isset($this->viewParams['pList'])) :?>

<table width = "100%">
<tr style="font-weight:bold">
<td width="3%">
Id
</td>
<td  width="50%">
<?=t(13)?>



</td>
<td  width="5%">
<?=t(2)?>
</td>
<td width="17%">
<?=t(14)?>
</td>
<td  width="25%">
Action
</td>
</tr>
<?foreach ($this->viewParams['pList'] as $node) :?>
	<? $node['metadata'] = unserialize($node['metadata']) ?>
<tr id="row-<?=$node['id']?>">

<td>
<?=$node['id'] ?>
</td>
<td>
<a href="<?=$this->hvnUrl(
	array("module" => "node", "action" => "view", "type" => $this->viewParams['nodeTypeInfo']['type']), 'node')?>?id=<?=$node['id'] ?>">
<?=$node['title'] ?>	
	</a>

</td>
<td>
	<select name="<?=$node['id'] ?>" id ="changeStatus">
		<option value='0'> <?=t(34) ?> </option>
		<option value='1'> <?=t(33) ?> </option>
		<option value='2'> <?=t(35) ?> </option>
		<option value='3'> <?=t(36) ?> </option>
	</select>
<!--</?= get_status_from_int ($node['status']) ?>-->
</td>
<td>
<?if(isset($node['metadata']['category_name'])) :?><?=p($node['metadata']['category_name']) ?><?endif?>
</td>
<td>

<?
		$sess = new Zend_Session_Namespace(CLU_NS);
		if ((isset($sess->userId) && 
			(strpos($sess->userPermissions, 'update ' . $this->viewParams['nodeTypeInfo']['type']) ||
			($sess->userId == $this->viewParams['node']->poster_id && strpos ($sess->userPermissions, 'update own ' . $this->viewParams['nodeTypeInfo']['type'])
			))))
:?>
 	<a href="javascript:void()" name="http://<?= SITE_URL . '/' . $sess->viewLang ?>/node/ajax/delete-node?type=<?=$this->viewParams['nodeTypeInfo']['type']?>&id=<?=$node['id']?>"
 	class="ajax-delete" title="<?=$node['id'] ?>"
 	> <?=t(31)?></a>
 	<a href="<?=$this->hvnUrl(array('module' => 'node',
 	                                'controller' => 'master',
 	                                'type' => $this->viewParams['nodeTypeInfo']['type'],
 	                                'action' => 'edit') ,
 	                                'node');?>?id=<?=$node['id']?>" > <?=t(38)?> </a>
 	<?if ($this->viewParams['nodeTypeInfo']['needs_translation']) :?>
 	<a href="<?=$this->hvnUrl(array('module' => 'article',
 	                                'controller' => 'master',
 	                                'action' => 'translate') ,
 	                                'nocontroller');?>?id=<?=$node['article_id']?>" > <?=t(90)?> </a>
 	<?endif ?>
 <?endif ?>

 	<?if ($this->viewParams['nodeTypeInfo']['type'] == 'gallery') :?>
 	<a href="<?=$this->hvnUrl(array('module' => 'gallery',
 	                                'action' => 'upload-photos') ,
 	                                'nocontroller');?>?id=<?=$node['id']?>" > <?=t(1027)?> </a>
 	
 	<?endif ?>

</td>
</tr>
<?endforeach?>
</table>


<?else :?>
<?if (isset($this->viewParams['resultErrorMessage'])) :?>
	<div class="errorMessage">
	<?=$this->viewParams['resultErrorMessage'] ?>
	</div>
<?endif ?>
<?endif ?>
</div>

<div>
<?if(isset($this->viewParams['paginator'])) :?>
	<?= $this->paginationControl($this->viewParams['paginator'], 'Sliding',
			 '/modules/common/views/scripts/commonTheme/commonLang/common/clu-pagination-control.phtml',
			 array('searchUrl' => $this->viewParams['searchUrl'])); ?>
<?endif?>
</div>
</div>
<script type="text/javascript">
$(function() {
    //val = $("#metadata").html();
    $(".ajax-delete").click(function(){
    	url = $(this).attr('name');
    	id = $(this).attr('title');
    	$.getJSON(url, {}, 
	    	function(data){
				if (data.success == false)
				{
					alert(data.errorMessage);
				}
				else
				{
					alert("Success" + "#row-" + id);
					$("#row-" + id).css("background-color","red").fadeOut(1000);
				}
    		});
    	});
    	
    //updated change status
    type = '<?=$this->viewParams['nodeTypeInfo']['type']?>';
    $("select#changeStatus").change(function(){
	    	status = $(this).attr('value');
	    	nodeId = $(this).attr('name');
	    	$.getJSON("/<?=$sess->viewLang?>/node/ajax/updated-status-node", {
	    		type: type,
	    		status: status,
	    		nodeId: nodeId,	
	    	}, 
	    	function(data){
				if (data.success == false)
				{
					alert(data.errorMessage);
				}
				else
				{
					alert(' Status ' + status);
				}
    	});
	});
});
</script>

